<template>
	<view class="content">
		<view class="content-box">
			<view class="title">
				{{data.title}}
			</view>
			<view class="detail">
				<text>{{data.user.username}}</text>
				<text>{{formatTime(data.createtime)}}</text>
				<text>发布于{{data.ip}}</text>
			</view>
			<view class="detail-box" v-html="data.content">
				
			</view>
		</view>
	</view>
</template>

<script>
	import {
		articleDetail
	} from "../../api/my.js";
	import ArticelDetail from '@/components/articel_detail'
	export default {
		components: {
			ArticelDetail
		},
		data() {
			return {
				articleid: '',
				data: {
					user:{
						username:''
					}
				}
			}
		},
		onLoad(option) {
			this.articleid = option.id
			this.getinfo()
		},
		methods: {
			async getinfo() {
				await articleDetail({
					'article_id': this.articleid
				}).then(res => {
					console.log('获取文章详情', res);
					this.data = res.data
				});
			},
			formatTime(timestamp) {
				const date = new Date(timestamp * 1000); // 将秒转换为毫秒
				const year = date.getFullYear();
				const month = (date.getMonth() + 1).toString().padStart(2, '0');
				const day = date.getDate().toString().padStart(2, '0');
				const hours = date.getHours().toString().padStart(2, '0');
				const minutes = date.getMinutes().toString().padStart(2, '0');
				const seconds = date.getSeconds().toString().padStart(2, '0');
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #e8f0fe;
		display: flex;
		justify-content: center;
	}

	.content-box {
		width: 85%;

		.title {
			margin-top: 60px;
			font-size: 20px;
			color: #444;
		}

		.detail {
			display: flex;
			justify-content: space-around;
			margin-top: 30px;
		}
		.detail-box{
			margin-top: 30px;
		}
	}
</style>